const cluster = require('cluster')
const http = require('http')
const numCPUs = parseInt(require('os').cpus().length * 0.7)

if (cluster.isMaster) {
  console.log(`主进程 ${process.pid} 正在运行`)

  // 衍生工作进程。
  for (let i = 0; i < numCPUs; i++) {
    cluster.fork()
  }

  cluster.on('fork', (worker) => {
    console.log('工作进程已关闭:', worker.isDead())
  });

  cluster.on('exit', (worker, code, signal) => {
    console.log('工作进程已关闭:', worker.isDead())
  });
} else {
  console.log('worker:', process.pid)
  require('./s')
}